<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>分销比例和金额-思途CMS{$coreVersion}</title>
 {template 'stourtravel/public/public_js'}
 {php echo Common::getCss('style.css,base.css,base2.css,plist.css,product.css,base_new.css'); }
 {php echo Common::getScript("uploadify/jquery.uploadify.min.js,jquery.buttonbox.js,choose.js,artDialog/dist/dialog-min.js"); }
 {php echo Common::getCss('ui-dialog.css','js/artDialog/css/'); }

</head>
<body style="overflow:hidden">
<table class="content-tab">
   <tr>
    <td width="119px" class="content-lt-td"  valign="top">
     {template 'stourtravel/public/leftnav'}
    <!--右侧内容区-->
    </td>
    <td valign="top" class="content-rt-td" style="overflow:hidden">
    	<div class="cfg-header-bar">
    		<div class="cfg-header-search">
    			<input type="text" id="searchkey" value="产品标题或编号" datadef="标题或产品ID" class="search-text">
                <a href="javascript:;" class="search-btn" onclick="CHOOSE.searchKeyword()">搜索</a>
    		</div>
    		<a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
<!--            <a href="javascript:;" id="addbtn" class="fr btn btn-primary radius mt-6 mr-10" >添加</a>-->
    	</div>
	     <span class="display-mod">
	
	     </span>
        </div>
 	<div id="product_grid_panel" class="content-nrt">
    
  	</div>
  </td>
  </tr>
 </table> 
<script>
   window.display_mode=1;	//默认显示模式
   window.product_kindid=0;  //默认目的地ID
   var level_num = "{$level_num}";
   var commissiontype={$commissiontype};
   var typeid="{$typeid}";
   var groupid="{$groupid}"

   {if !empty($people_group)}
     var people_group = {json_encode($people_group)};
   {/if}


  Ext.onReady(
    function() 
    {
		 Ext.tip.QuickTipManager.init();

        $(".btnbox").buttonBox();

        $("#searchkey").focusEffect();
        //添加按钮
		//产品store
        window.product_store=Ext.create('Ext.data.Store',{

		 fields:[
             'id',
             'title',
             'webid',
             'url',
             'modtime',
             'fxratio1',
             'fxratio2',
             'fxratio3',
             'fxratio',
             'pm_fxratio1',
             'pm_fxratio2',
             'pm_fxratio3',
             'pm_fxratio',
             'cash1',
             'cash2',
             'cash3',
             'cash',
             'cash_child',
             'cash_old',
             'cash1_child',
             'cash1_old',
             'cash2_child',
             'cash2_old',
             'cash3_child',
             'cash3_old',


             'cash_people4',
             'cash_people5',
             'cash_people6',

             'cash1_people4',
             'cash1_people5',
             'cash1_people6',

             'cash2_people4',
             'cash2_people5',
             'cash2_people6',

             'cash3_people4',
             'cash3_people5',
             'cash3_people6',
             
             'displayorder'
         ],
         proxy:{
		   type:'ajax',
           extraParams:{typeid:typeid,groupid:groupid},
		   api: {
              read: SITEURL+'fenxiao/admin/product/list/action/read',  //读取数据的URL
			  update:SITEURL+'fenxiao/admin/product/list/action/save',
			  destroy:SITEURL+'fenxiao/admin/product/list/action/delete'
              },
		      reader:{
                type: 'json',   //获取数据的格式 
                root: 'lists',
                totalProperty: 'total'
                }	
	         },
		 remoteSort:true,
         autoLoad:true,
		 pageSize:30,
         listeners:{
                load:function( store, records, successful, eOpts )
                {
                    if(!successful){
                        ST.Util.showMsg("{__('norightmsg')}",5,1000);
                    }
                    var pageHtml = ST.Util.page(store.pageSize, store.currentPage, store.getTotalCount(), 10);
                    $("#line_page").html(pageHtml);
                    window.product_grid.doLayout();

                    $(".pageContainer .pagePart a").click(function () {
                        var page = $(this).attr('page');
                        product_store.loadPage(page);
                    });
                }
            }
       });
	   
	  //产品列表 
	  window.product_grid=Ext.create('Ext.grid.Panel',{ 
	   store:product_store,
	   renderTo:'product_grid_panel',
	   border:0,
	   bodyBorder:0,
	   bodyStyle:'border-width:0px',
       scroll:'vertical', //只要垂直滚动条
	   bbar: Ext.create('Ext.toolbar.Toolbar', {
                    store: product_store,  //这个和grid用的store一样
                    displayInfo: true,
                    emptyMsg: "",
					items:[
                        {
                            xtype:'panel',
                            id:'listPagePanel',
                            html:'<div id="line_page"></div>'
                        },
					   {
						  xtype:'combo',
						  fieldLabel:'每页显示数量',
						  width:170,
						  labelAlign:'right',
						  forceSelection:true,
						  value:30,  
						  store:{fields:['num'],data:[{num:30},{num:60},{num:100}]},
						  displayField:'num',
						  valueField:'num',
						  listeners:{
							  select:CHOOSE.changeNum
						  }
					  }
					
					],
				  listeners: {
						single: true,
						render: function(bar) {
							var items = this.items;
							//bar.down('tbfill').hide();

							bar.insert(0,Ext.create('Ext.panel.Panel',{border:0,html:'<div class="panel_bar"><a class="btn btn-primary radius" href="javascript:void(0);" onclick="CHOOSE.chooseAll()">全选</a><a class="btn btn-primary radius ml-10" href="javascript:void(0);" onclick="setFenxiao()">批量设置</a></div>'}));
							bar.insert(1,Ext.create('Ext.toolbar.Fill'));
							//items.add(Ext.create('Ext.toolbar.Fill'));
						}
					}	
                 }), 		 			 
	   columns:[
			   {
				   text:'选择',
				   width:'5%',
				  // xtype:'templatecolumn',
				   tdCls:'product-ch',
				   align:'center',
				   dataIndex:'id',
				   border:0,
                   menuDisabled:true,
				   renderer : function(value, metadata,record) {
					    var id=record.get('id');
					    return  "<input type='checkbox' class='product_check' id='box_"+id+"' style='cursor:pointer' value='"+value+"'/>";
					}
			   },
               {
                   text:'排序',
                   width:'5%',
                   dataIndex:'displayorder',
                   align:'center',
                   cls:'sort-col',
                   menuDisabled:true,
                   border:0,
                   sortable:true,
                   renderer : function(value, metadata,record) {
                       var id=record.get('id');
                       var newvalue=value;
                       if(!value || value==9999||value==999999)
                       {
                           newvalue = '';
                       }
                       return "<input type='text' onkeyup=\"if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\\D/g,'')}\" onafterpaste=\"if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'0')}else{this.value=this.value.replace(/\\D/g,'')}\" value='"+newvalue+"' class='row-edit-txt' onblur=\"updateField(this,'"+id+"','displayorder',0,'input')\"/>";
                   }
               },
               {
                   text:'产品ID',
                   width:'5%',
                   dataIndex:'id',
                   align:'center',
                   menuDisabled:true,
                   border:0,
                   sortable:false,
                   renderer : function(value, metadata,record) {
                      return value;
                   }
               },
			   {
				   text:'标题',
				   width:'15%',
				   dataIndex:'title',
				   align:'left',
                   menuDisabled:true,
				   border:0,
				   sortable:false,
				   renderer : function(value, metadata,record) {
                               var url=record.get('url');
			                   return "<a href='"+url+"' class='line-title' target='_blank'>"+value+"</a>";
						},
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(level_num==2)
                           {
                               obj.width='32%';
                           }

                       }
                   }
			   },
               {
                   text: '直属上级佣金比例',
                   width: '18%',
                   dataIndex: 'fxratio1',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;
                       return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','fxratio1',0,'input')\"/><span style='color:green'> %<span>";

                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(commissiontype!=1)
                               obj.hide();
                           else
                               obj.show();
                       }
                   }
               },
               {
                   text: '二级上级佣金比例',
                   width: '18%',
                   dataIndex: 'fxratio2',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;
                       return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','fxratio2',0,'input')\"/><span style='color:green'> %<span>";

                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(commissiontype!=1)
                               obj.hide();
                           else
                               obj.show();

                       }
                   }
               },
               {
                   text: '三级上级佣金比例',
                   width: '18%',
                   dataIndex: 'fxratio3',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;
                       return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit' onblur=\"updateField(this,'" + id + "','fxratio3',0,'input')\"/><span style='color:green'> %<span>";
                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(commissiontype!=1 || level_num==2)
                               obj.hide();
                           else
                               obj.show();

                       }
                   }
               },
           {
               text: '自购佣金比例',
               width: '18%',
               dataIndex: 'fxratio',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;
                   return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit' onblur=\"updateField(this,'" + id + "','fxratio',0,'input')\"/><span style='color:green'> %<span>";
               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=1)
                           obj.hide();
                       else
                           obj.show();

                   }
               }
           },
           {
               text: '直属上级佣金比例',
               width: '18%',
               dataIndex: 'pm_fxratio1',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;
                   return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','pm_fxratio1',0,'input')\"/><span style='color:green'> %<span>";

               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=2)
                           obj.hide();
                       else
                           obj.show();
                   }
               }
           },
           {
               text: '二级上级佣金比例',
               width: '18%',
               dataIndex: 'pm_fxratio2',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;
                   return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','pm_fxratio2',0,'input')\"/><span style='color:green'> %<span>";

               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=2)
                           obj.hide();
                       else
                           obj.show();

                   }
               }
           },
           {
               text: '三级上级佣金比例',
               width: '18%',
               dataIndex: 'pm_fxratio3',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;
                   return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit' onblur=\"updateField(this,'" + id + "','pm_fxratio3',0,'input')\"/><span style='color:green'> %<span>";
               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=2 || level_num==2)
                           obj.hide();
                       else
                           obj.show();

                   }
               }
           },
           {
               text: '自购佣金比例',
               width: '18%',
               dataIndex: 'pm_fxratio',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;
                   return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit' onblur=\"updateField(this,'" + id + "','pm_fxratio',0,'input')\"/><span style='color:green'> %<span>";
               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=2)
                           obj.hide();
                       else
                           obj.show();
                   }
               }
              },
               {
                   text: '直属上级佣金',
                   width: '17%',
                   dataIndex: 'cash1',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;



                       if(typeid==1 && people_group)
                       {
                           var html = '<table><tr>';
                           var cash_fields = {2:'cash1',1:'cash1_child',3:'cash1_old'};

                           var index=0;
                           for(var i in people_group)
                           {
                               index++;

                               if(index==4)
                               {
                                   html+='</tr></tr>';
                               }

                               var people_row = people_group[i];
                               var cash_field = i<4? cash_fields[i]:'cash1_people'+people_row['identifier'];
                               var cash_val = record.get(cash_field);
                               cash_val = !cash_val?'':cash_val;
                               html+='<td align="left">'+people_row['name']+"</td><td align='left'><input type='text' value='" + cash_val + "' class='row-edit-txt' style='width:50px'  onblur=\"updateField(this,'" + id + "','"+cash_field+"',0,'input')\"/></td>";
                           }

                           if(index>3 && index<6)
                           {
                               for(var i=0;i++;i<6-index)
                               {
                                   html+='<td></td><td></td>';
                               }
                           }

                           html+='</tr></table>'
                           return html;


                       }
                       else
                       {
                           return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','cash1',0,'input')\"/><span> 元<span>";
                       }

                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {


                           if(commissiontype!=0)
                               obj.hide();
                           else
                               obj.show();

                       }
                   }
               },
               {
                   text: '二级上级佣金',
                   width: '17%',
                   dataIndex: 'cash2',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;
                       var cash2_old=record.get('cash2_old');
                       var cash2_child=record.get('cash2_child');
                       cash2_old=!cash2_old?'':cash2_old;
                       cash2_child=!cash2_child?'':cash2_child;
                       if(typeid==1 && people_group)
                       {
                           var html =  '<table><tr>';
                           var cash_fields = {2:'cash2',1:'cash2_child',3:'cash2_old'};

                           var index=0;
                           for(var i in people_group)
                           {
                               index++;
                               if(index==4)
                               {
                                   html+='</tr></tr>';
                               }
                               var people_row = people_group[i];
                               var cash_field = i<4? cash_fields[i]:'cash2_people'+people_row['identifier'];
                               var cash_val = record.get(cash_field);
                               cash_val = !cash_val?'':cash_val;
                               html+= '<td align="left">'+people_row['name']+"</td><td align='left'><input type='text' value='" + cash_val + "' class='row-edit-txt' style='width:50px'  onblur=\"updateField(this,'" + id + "','"+cash_field+"',0,'input')\"/></td>";

                           }
                           if(index>3 && index<6)
                           {
                               for(var i=0;i++;i<6-index)
                               {
                                   html+='<td></td><td></td>';
                               }
                           }
                           html+='</tr></table>'
                           return html;


                       }
                       else
                       {
                           return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','cash2',0,'input')\"/><span> 元<span>";
                       }
                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(commissiontype!=0)
                               obj.hide();
                           else
                               obj.show();

                       }
                   }
               },
               {
                   text: '三级上级佣金',
                   width: '17%',
                   dataIndex: 'cash3',
                   align: 'center',
                   border: 0,
                   cls: 'mod-2 sort-col',
                   menuDisabled: true,
                   sortable: true,
                   renderer: function (value, metadata, record) {
                       var id = record.get('id');
                       value = !value ? '' : value;
                       var cash3_old=record.get('cash3_old');
                       var cash3_child=record.get('cash3_child');
                       cash3_old=!cash3_old?'':cash3_old;
                       cash3_child=!cash3_child?'':cash3_child;

                       if(typeid==1 && people_group)
                       {
                           var html =  '<table><tr>';
                           var cash_fields = {2:'cash3',1:'cash3_child',3:'cash3_old'};

                           var index=0;
                           for(var i in people_group)
                           {
                               index++;
                               if(index==4)
                               {
                                   html+='</tr></tr>';
                               }
                               var people_row = people_group[i];
                               var cash_field = i<4? cash_fields[i]:'cash3_people'+people_row['identifier'];
                               var cash_val = record.get(cash_field);
                               cash_val = !cash_val?'':cash_val;
                               html+=  '<td align="left">'+people_row['name']+"</td><td align='left'><input type='text' value='" + cash_val + "' class='row-edit-txt' style='width:50px'  onblur=\"updateField(this,'" + id + "','"+cash_field+"',0,'input')\"/></td>";
                           }
                           if(index>3 && index<6)
                           {
                               for(var i=0;i++;i<6-index)
                               {
                                   html+='<td></td><td></td>';
                               }
                           }
                           html+='</tr></table>'
                           return html;
                       }
                       else
                       {
                           return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','cash3',0,'input')\"/><span> 元<span>";
                       }

                   },
                   listeners:{
                       afterrender:function(obj,eopts)
                       {
                           if(commissiontype!=0 || level_num==2)
                               obj.hide();
                           else
                               obj.show();

                       }
                   }
               },
           {
               text: '自购佣金',
               width: '19%',
               dataIndex: 'cash',
               align: 'center',
               border: 0,
               cls: 'mod-2 sort-col',
               menuDisabled: true,
               sortable: true,
               renderer: function (value, metadata, record) {
                   var id = record.get('id');
                   value = !value ? '' : value;

                   var cash_old=record.get('cash_old');
                   var cash_child=record.get('cash_child');
                   cash_old=!cash_old?'':cash_old;
                   cash_child=!cash_child?'':cash_child;
                   if(typeid==1 && people_group)
                   {
                       var html =  '<table><tr>';
                       var cash_fields = {2:'cash',1:'cash_child',3:'cash_old'};

                       var index=0;
                       for(var i in people_group)
                       {
                           index++;
                           if(index==4)
                           {
                               html+='</tr></tr>';
                           }
                           var people_row = people_group[i];
                           var cash_field = i<4? cash_fields[i]:'cash_people'+people_row['identifier'];
                           var cash_val = record.get(cash_field);
                           cash_val = !cash_val?'':cash_val;

                           html+= '<td align="left">'+people_row['name']+"</td><td align='left'><input type='text' value='" + cash_val + "' class='row-edit-txt' style='width:50px'  onblur=\"updateField(this,'" + id + "','"+cash_field+"',0,'input')\"/></td>";
                       }

                       if(index>3 && index<6)
                       {
                           for(var i=0;i++;i<6-index)
                           {
                               html+='<td></td><td></td>';
                           }
                       }
                       html+='</tr></table>'
                       return html;


                   }
                   else
                   {
                       return "<input type='text' value='" + value + "' class='row-edit-txt fx-ratio-edit'  onblur=\"updateField(this,'" + id + "','cash',0,'input')\"/><span> 元<span>";
                   }
               },
               listeners:{
                   afterrender:function(obj,eopts)
                   {
                       if(commissiontype!=0)
                           obj.hide();
                       else
                           obj.show();

                   }
               }
           }
              ],
			 listeners:{
		            boxready:function()
		            {
					   var height=Ext.dom.Element.getViewportHeight();
					   this.maxHeight=height-40;
					   this.doLayout();
		            },
					afterlayout:function(grid)
					{
			            if(window.product_kindname)
						{
							 //Ext.getCmp('column_lineorder').setText(window.product_kindname+'-排序')
						}
						else
					    {
							//Ext.getCmp('column_lineorder').setText('排序')
						}
					
						/*window.product_store.each(function(record){
				        id=record.get('id');
						

						
					   });*/
					   var data_height=0;
					   try{
					     data_height=grid.getView().getEl().down('.x-grid-table').getHeight();
					   }catch(e)
					   {
					   }
					  var height=Ext.dom.Element.getViewportHeight();

					  if(data_height>height-40)
					  {
						  window.has_biged=true;
						  grid.height=height-40;
					  }
					  else if(data_height<height-40)
					  {
						  if(window.has_biged)
						  {
							window.has_biged=false;  
							grid.doLayout();
						  }
					  }
				  }
			 },
			 plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                  clicksToEdit:2,
                  listeners:{
					 edit:function(editor, e)
					 {
						var id=e.record.get('id');
						updateField(0,id,e.field,e.value,0);
						return false;
						  
					 },
					 beforeedit:function(editor,e)
					 {
								   
					 }
				 }
               })
             ],
			viewConfig:{
				//enableTextSelection:true
				}	   
	   });
	   
	  
	  
	})
	
	//实现动态窗口大小
  Ext.EventManager.onWindowResize(function(){
      var height=Ext.dom.Element.getViewportHeight();
	  var data_height=window.product_grid.getView().getEl().down('.x-grid-table').getHeight();
      if(data_height>height-40)
          window.product_grid.height=(height-40);
      else
          delete window.product_grid.height;
      window.product_grid.doLayout();
	 }) 
	
  $("#fx_products").change(function(){
      var tid=$(this).val();
      typeid=tid;
    //  product_store.getProxy().setExtraParam('typeid',typeid);
      //product_store.loadPage(1);
      var url=SITEURL+'fenxiao/admin/product/list/typeid/'+tid+'/parentkey/fenxiao/itemid/5';
      window.location.href=url;
  });
  //更新某个字段
  function updateField(ele,id,field,value,type,callback)
  {
	  var record=window.product_store.getById(id.toString());
	  if(type=='select'||type=='input')
	  {
		  value=Ext.get(ele).getValue();
	  }
	  var view_el=window.product_grid.getView().getEl();
	  Ext.Ajax.request({
						 url   :  SITEURL+"fenxiao/admin/product/list/action/update",
						 method  :  "POST",
						 datatype  :  "JSON",
						 params:{id:id,field:field,val:value,typeid:typeid,groupid:groupid},
						 success  :  function(response, opts) 
						 {
							 if(response.responseText=='ok')
							 {
							   record.set(field,value);
							   record.commit();
                               if(typeof(callback)=='function')
                               {
                                   callback(record);
                               }
						      
							 }
                             else
                             {
                                 ST.Util.showMsg("{__('norightmsg')}",5,1000);
                             }
						 }});
  }
   function updateFields(id,data)
   {
       var record=window.product_store.getById(id.toString());
       var view_el=window.product_grid.getView().getEl();
       data['id']=id;
       data['typeid']=typeid;
       data['groupid']=groupid;
       Ext.Ajax.request({
           url   :  SITEURL+"fenxiao/admin/product/list/action/updatesome",
           method  :  "POST",
           datatype  :  "JSON",
           params:data,
           success  :  function(response, opts)
           {
               if(response.responseText=='ok')
               {
                   for(var i in data) {
                       record.set(i, data[i]);
                       record.commit();
                       if (typeof(callback) == 'function') {
                           callback(record);
                       }
                   }
               }
               else
               {
                   ST.Util.showMsg("{__('norightmsg')}",5,1000);
               }
           }});
   }



    function setFenxiao()
    {
        if($(".product_check:checked").length<=0)
        {
            ST.Util.showMsg("请至少选择一个产品",5,1000);
            return;
        }
        var content='<div class="item-one" id="ratio_set_con"><table>';

        if(commissiontype==1) {
            content +='<tr><td class="tit">直属上级佣金比例：</td><td><input type="text" name="fxratio1" id="set_fxratio1" class="set-text-xh  text_60" value=""><span style="color:green"> %</span></td></tr>' +
            '<tr><td class="tit">二级上级佣金比例：</td><td><input type="text" name="fxratio2"  id="set_fxratio2" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td></tr>';
            if (level_num == 3) {
                content += '<tr><td class="tit">三级上级佣金比例：</td><td><input type="text" name="fxratio3"  id="set_fxratio3" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td></tr>';
            }

            content += '<tr><td class="tit">自购佣金比例：</td><td><input type="text" name="fxratio"  id="set_fxratio" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td></tr>';

        }
        else if(commissiontype==2)
        {
            content +='<tr>' +
            '<td class="tit">直属上级佣金比例：</td><td><input type="text" name="pm_fxratio1" id="set_fxratio1" class="set-text-xh  text_60" value=""><span style="color:green"> %</span></td>' +
            '</tr>' +
            '<tr>' +
            '<td class="tit">二级上级佣金比例：</td><td><input type="text" name="pm_fxratio2"  id="set_fxratio2" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td>' +
            '</tr>';
            if (level_num == 3) {
                content += '<tr><td class="tit">三级上级佣金比例：</td><td><input type="text" name="pm_fxratio3"  id="set_fxratio3" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td></tr>';
            }
            content += '<tr><td class="tit">自购佣金比例：</td><td><input type="text" name="pm_fxratio"  id="set_fxratio" class="set-text-xh text_60" value=""><span style="color:green"> %</span></td></tr>';

        }
        else
        {

            if(typeid!=1)
            {
                content+= '<tr><td class="tit">直属上级佣金：</td><td><input type="text" name="cash1" id="set_cash1" class="set-text-xh  text_60" value=""></td></tr>';
                content+=  '<tr><td class="tit">二级上级佣金：</td><td><input type="text" name="cash2"  id="set_cash2" class="set-text-xh text_60" value=""></td></tr>';
                if(level_num==3)
                {
                    content+='<tr><td class="tit">三级上级佣金：</td><td><input type="text" name="cash3"  id="set_cash3" class="set-text-xh text_60" value=""></td></tr>';
                }
            }
            else {


                var cash1_fields = {2:'cash1',1:'cash1_child',3:'cash1_old'};
                content += '<tr><td class="tit">直属上级佣金：</td>';
                for (var i in people_group)
                {
                    var people = people_group[i];
                    var cash_field = i<4? cash1_fields[i]:'cash1_people'+people['identifier'];
                    content+='<td><label class="fl ml-5 mt-5">'+people['name']+': </label><input type="text" name="'+cash_field+'"  class="set-text-xh  text_60 ml-5 mt-5" value=""></td>';
                }
                content +='</tr>';


                var cash2_fields = {2:'cash2',1:'cash2_child',3:'cash2_old'};
                content +=  '<tr><td class="tit">二级上级佣金：</td>';
                for (var i in people_group)
                {
                    var people = people_group[i];
                    var cash_field = i<4? cash2_fields[i]:'cash2_people'+people['identifier'];
                    content+='<td><label class="fl ml-5 mt-5">'+people['name']+': </label><input type="text" name="'+cash_field+'"  class="set-text-xh  text_60 ml-5 mt-5" value=""></td>';
                }
                content += '</tr>';

                if(level_num==3)
                {
                    var cash3_fields = {2:'cash3',1:'cash3_child',3:'cash3_old'};
                    content+='<tr><td class="tit">三级上级佣金：</td>';
                    for (var i in people_group)
                    {
                        var people = people_group[i];
                        var cash_field = i<4? cash3_fields[i]:'cash3_people'+people['identifier'];
                        content+='<td><label class="fl ml-5 mt-5">'+people['name']+': </label><input type="text" name="'+cash_field+'"  class="set-text-xh  text_60 ml-5 mt-5" value=""></td>';
                    }
                    content+='</tr>';
                }

                var cash_fields = {2:'cash',1:'cash_child',3:'cash_old'};
                content +=  '<tr><td class="tit">自购佣金：</td>';
                for (var i in people_group)
                {
                    var people = people_group[i];
                    var cash_field = i<4? cash_fields[i]:'cash_people'+people['identifier'];
                    content+='<td><label class="fl ml-5 mt-5">'+people['name']+': </label><input type="text" name="'+cash_field+'"  class="set-text-xh  text_60 ml-5 mt-5" value=""></td>';
                }
                content += '</tr>';
            }

        }
        content+= '</table>' +
            '<div class="save-con"><a href="javascript:;" class="confirm-btn" id="ratio_set_btn">确定</a></div>' +
            '</div>';

        var dlg = parent.dialog({
            title: '批量设置',
            content: content,
            onshow:function(){
                   $("#ratio_set_btn",parent.document).click(function(){

                       var data = {};
                       $("#ratio_set_con input",parent.document).each(function(index,ele){
                           var name = $(ele).attr('name');
                           var val = $(ele).val();
                           data[name] = val;
                       });
                       console.log(data);

                          $(".product_check:checked").each(function(){
                               var id=$(this).val();
                               updateFields(id,data)
                          })
                         dlg.remove();
                   });
            }
        });
        dlg.showModal();
        //var url = SITEURL+'product/dialog_setratio/typeid/1/'
        //CHOOSE.setSome("设置分销",null,url,1);
    }


</script>

</body>
</html>
